package main

import (
	"flag"
	"github.com/rs/zerolog/log"
	"zatta-gateway/application"
	"zatta-gateway/config"
	"zatta-gateway/http"
)

var gatewayHostPort = flag.String("host_port", "50050", "gateway server start at this port")
var machineTag = flag.String("machine_tag", "zatta-gateway", "machine tag")
var debug = flag.Bool("debug", false, "debug mode")
var cors = flag.Bool("cors", true, "enable cors")
var dbConfigPath = flag.String("db_config_path", "./config", "db config path")

func main() {
	flag.Parse()

	opts := []config.AppOption{
		config.WithDBConfigPath(*dbConfigPath),
		config.WithCors(*cors),
		config.WithDebug(*debug),
		config.WithMachineTag(*machineTag),
	}
	app, err := application.New(opts...)

	if err != nil {
		log.Error().Msgf("error during App Construction,err:%s", err)
	}
	appHTTP, err := http.API(app)
	if err != nil {
		log.Error().Msgf("error during HTTP App Construction,err:%s", err)
	}
	if err = appHTTP.Listen(":" + *gatewayHostPort); err != nil {
		log.Error().Msgf("error during HTTP App Listen,err:%s", err)
	}
}
